#ifndef PROCESSSOUND_H_INCLUDED
#define PROCESSSOUND_H_INCLUDED


#include "BufferedDevice.h"
#include "WaveFormat.h"
#include "Active.h"
#include <fftw3.h>


class ProcessSound: public ActiveObject
{
public:
    ProcessSound (wxGauge *newGauge);
	~ProcessSound ();

	wxGauge *theGauge;

    void ReInit () throw ();

	void SetFormat (
        unsigned samplesPerBuf,
        unsigned samplesPerSec,
        unsigned fftPoints,
        unsigned bitsPerSample) throw ();

	void GetFormat (unsigned & samplesPerSec, unsigned & bitsPerSample)
	{
		Win::Lock lock (_critSect);
		samplesPerSec = _format.SamplesPerSec ();
		bitsPerSample = _format.BitsPerSample ();
	}

    bool Start () throw ();
    void Stop ();
    int level;
    std::vector<int>		_outBuf;

    int HzToPoint (int hz)
    {
        Win::Lock lock (_critSect);
        //return _fftTransformer->HzToPoint (hz);
        return 0;
    }

    unsigned Points ()
    {
        Win::Lock lock (_critSect);
        //return _fftTransformer->Points ();
        return 0;
    }

	unsigned SamplesPerBuf ()
	{
        Win::Lock lock (_critSect);
		return _samplesPerBuf;
	}

private:
    void InitThread () {}
    void Run ();
    void FlushThread ();

    void LokWaveInData ();
private:

    Wave::BufferedDevice	_source;
    unsigned	_fftPoints;
    bool		_changed;
    Wave::Format _format;
    unsigned	_samplesPerBuf;



	Win::CritSect    _critSect;
	Win::Event       _event;
	std::auto_ptr<Wave::AsyncDevice> _device;

  fftw_complex *in, *out;
  fftw_plan p;
};


#endif // PROCESSSOUND_H_INCLUDED
